//
//  JDDetailModel.swift
//  LeGou
//
//  Created by 刘亿前 on 2022/9/20.
//

import Foundation

struct JDGoodsModel: HandyJSON {
    // 品牌code
    var brandCode = ""
    // 品牌名
    var brandName = ""
    //
    var cid1 = 0
    var cid1Name = ""
    var cid2 = 0
    var cid2Name = ""
    var cid3 = 0
    var cid3Name = ""
    // 评论数
    var comments = 0
    // 佣金
    var commission = 0.0
    // 佣金比例
    var commissionShare = 0.0
    var couponCommission = 0.0
    // 优惠券信息
    var couponInfo: JDGoodsCouponModel?
    var createTime = ""
    var deliveryType = 0
    var eliteId = 0
    var endTime = 0
    var forbidTypes = ""
    var goodCommentsShare = 0
    var historyPriceDay = 0
    // 图片信息
    var imageInfo: JDGoodsImgModel?
    // 详情banner
    var detailImages = ""
    // 30天销量
    var inOrderCount30Days = 0
    var inOrderCount30DaysSku = 0
    var isHot = 0
    var isLock = 0
    var lowestCouponPrice = 0.0
    var lowestPrice = 0.0
    var lowestPriceType = 0
    var materialUrl = ""
    var owner = ""
    var plusCommissionShare = 0
    var price = 0.0
    var resourceInfo = ""
    var shopInfo = ""
    var skuId = 0
    var skuLabelInfo = ""
    var skuName = ""
    var spuid = 0
    var startTime = 0
    var updateTime = ""
    var couponCommissionShare = 0.0
    var quotaShare = 0.0
    
    mutating func mapping(mapper: HelpingMapper) {
        mapper <<<
            self.imageInfo <-- TransformOf<JDGoodsImgModel, Any>(fromJSON: { (value) -> JDGoodsImgModel? in
                if let val = value as? String {
                    return JSONDeserializer<JDGoodsImgModel>.deserializeFrom(json: val)
                }
                if let val = value as? [String: Any] {
                    return JSONDeserializer<JDGoodsImgModel>.deserializeFrom(dict: val)
                }
                return nil
            }, toJSON: { (theCode) -> String? in
                return theCode?.toJSONString()
            })
        mapper <<<
            self.couponInfo <-- TransformOf<JDGoodsCouponModel, Any>(fromJSON: { (value) -> JDGoodsCouponModel? in
                if let val = value as? String {
                    return JSONDeserializer<JDGoodsCouponModel>.deserializeFrom(json: val)
                }
                if let val = value as? [String: Any] {
                    var info = JDGoodsCouponModel()
                    if let conpon = JSONDeserializer<JDGoodsCouponListModel>.deserializeFrom(dict: val) {
                        info.couponList = [conpon]
                    }
                    return info
                }
                return nil
            }, toJSON: { (theCode) -> String? in
                return theCode?.toJSONString()
            })
        mapper <<<
            self.lowestCouponPrice <-- ["lowestCouponPrice", "lowest_coupon_price"]
        mapper <<<
            self.lowestPrice <-- ["lowestPrice", "lowest_price"]
    }
}

struct JDGoodsImgModel: HandyJSON {
    var whiteImage = ""
    var imageList = [JDGoodsImgListModel]()
}

struct JDGoodsImgListModel: HandyJSON {
    var url = ""
}

struct JDGoodsCouponModel: HandyJSON {
    var couponList = [JDGoodsCouponListModel]()
}

struct JDGoodsCouponListModel: HandyJSON {
    // 券种类 (优惠券种类：0 - 全品类，1 - 限品类（自营商品），2 - 限店铺，3 - 店铺限商品券)
    var bindType = 0
    // 券面额
    var discount = 0.0
    // 券链接
    var link = ""
    // 券使用平台 (平台类型：0 - 全平台券，1 - 限平台券)
    var platformType = 0
    // 券消费限额
    var quota = 0.0
    // 领取开始时间(时间戳，毫秒)
    var getStartTime = 0
    // 券领取结束时间(时间戳，毫秒)
    var getEndTime = 0
    // 券有效使用开始时间(时间戳，毫秒)
    var useStartTime = 0
    // 券有效使用结束时间(时间戳，毫秒)
    var useEndTime = 0
    // 最优优惠券，1：是；0：否，购买一件商品可使用的面额最大优惠券
    var isBest = 1
    // 券热度，值越大热度越高，区间:[0,10]
    var hotValue = 0
}
